package com.example.ks.controller;

import com.example.ks.entity.Emp;
import com.example.ks.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/emp")
public class empcontroller {
    @Autowired
    private empservice empService;

    // 新增员工
    @PostMapping
    public boolean addEmp(@RequestBody Emp emp) {
        return empService.save(emp);
    }

    // 删除员工
    @DeleteMapping("/{id}")
    public boolean deleteEmp(@PathVariable Integer id) {
        return empService.removeById(id);
    }

    // 修改员工
    @PutMapping
    public boolean updateEmp(@RequestBody Emp emp) {
        return empService.updateById(emp);
    }

    // 根据ID查询员工
    @GetMapping("/{id}")
    public Emp getEmpById(@PathVariable Integer id) {
        return empService.getById(id);
    }

    // 查询所有员工
    @GetMapping
    public List<Emp> getAllEmps() {
        return empService.list();
    }
}